package cn.t.dto.user;


import cn.t.core.mode.BaseDTO;
import cn.t.vo.user.ResourceTreeVO;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @author l
 */
@Data
@JsonIgnoreProperties(value = {"gmtModifiedStart", "gmtModifiedEnd", "gmtCreatedStart", "gmtCreatedEnd"}, allowSetters = true)
public class ParticipantInfoDTO extends BaseDTO implements Serializable {


    /**
     * 用户ID
     */
    private Long userId;


    /**
     * 场景ID
     */
    private Integer scenarioId;


    /**
     * 客户ID
     */
    private Long individualId;


    /**
     * 公司ID
     */
    private Long firmId;

    private Long costCenterId;

    /**
     * 部门ID
     */
    private Long deptId;

    /**
     * 参与者状态 0-失效 1-有效
     */
    private String status;

    /**
     * 变更时间起(查询用)
     */
    private Date gmtModifiedStart;
    /**
     * 变更时间止(查询用)
     */
    private Date gmtModifiedEnd;
    /**
     * 创建时间起(查询用)
     */
    private Date gmtCreatedStart;
    /**
     * 创建时间止(查询用)
     */
    private Date gmtCreatedEnd;

    private List<ResourceTreeVO> resourceTreeList;

    public boolean hasRole(Long resourceId) {
        if (resourceTreeList == null || resourceTreeList.isEmpty()) {
            return false;
        }

        for (ResourceTreeVO resourceTreeVO : resourceTreeList) {
            if (hasRole(resourceId, resourceTreeVO)) {
                return true;
            }
        }
        return false;
    }

    private boolean hasRole(Long resourceId, ResourceTreeVO vo) {
        if (resourceId.equals(vo.getResourceId()) && vo.getHasRights()) {
            return true;
        }

        if (vo.getChildren() != null && !vo.getChildren().isEmpty()) {
            for (ResourceTreeVO child : vo.getChildren()) {
                if (hasRole(resourceId, child)) {
                    return true;
                }
            }
        }
        return false;
    }
}

